package com.rt.web.controller.system;

import java.util.List;

import com.rt.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rt.common.annotation.Log;
import com.rt.common.core.controller.BaseController;
import com.rt.common.core.domain.AjaxResult;
import com.rt.common.enums.BusinessType;
import com.rt.system.domain.RtAnswerData;
import com.rt.system.service.IRtAnswerDataService;
import com.rt.common.utils.poi.ExcelUtil;
import com.rt.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 作答结果数据（难易度调整用）Controller
 * 
 * @author Yg
 * @date 2022-04-21
 */
@RestController
@RequestMapping("/system/data")
public class RtAnswerDataController extends BaseController
{
    @Autowired
    private IRtAnswerDataService rtAnswerDataService;

    /**
     * 查询作答结果数据（难易度调整用）列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(RtAnswerData rtAnswerData)
    {
        startPage();
        List<RtAnswerData> list = rtAnswerDataService.selectRtAnswerDataList(rtAnswerData);
        return getDataTable(list);
    }

    /**
     * 导出作答结果数据（难易度调整用）列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "作答结果数据（难易度调整用）", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RtAnswerData rtAnswerData)
    {
        List<RtAnswerData> list = rtAnswerDataService.selectRtAnswerDataList(rtAnswerData);
        ExcelUtil<RtAnswerData> util = new ExcelUtil<RtAnswerData>(RtAnswerData.class);
        return util.exportExcel(list, "作答结果数据（难易度调整用）数据");
    }

    @Log(title = "作答结果数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:data:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<RtAnswerData> util = new ExcelUtil<RtAnswerData>(RtAnswerData.class);
        List<RtAnswerData> rtAnswerData = util.importExcel(file.getInputStream());
        String message = rtAnswerDataService.importRtAnswerData(rtAnswerData, getUsername());
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<RtAnswerData> util = new ExcelUtil<RtAnswerData>(RtAnswerData.class);
        return util.importTemplateExcel("作答结果");
    }

    /**
     * 获取作答结果数据（难易度调整用）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rtAnswerDataService.selectRtAnswerDataById(id));
    }

    /**
     * 新增作答结果数据（难易度调整用）
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "作答结果数据（难易度调整用）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RtAnswerData rtAnswerData)
    {
        return toAjax(rtAnswerDataService.insertRtAnswerData(rtAnswerData));
    }

    /**
     * 修改作答结果数据（难易度调整用）
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "作答结果数据（难易度调整用）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RtAnswerData rtAnswerData)
    {
        return toAjax(rtAnswerDataService.updateRtAnswerData(rtAnswerData));
    }

    /**
     * 删除作答结果数据（难易度调整用）
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "作答结果数据（难易度调整用）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rtAnswerDataService.deleteRtAnswerDataByIds(ids));
    }
}
